From 5007e48c8546d8138092039bf3cecc0b9904a407 Mon Sep 17 00:00:00 2001 From: Factiven Date: Thu, 13 Apr 2023 22:14:50 +0700 Subject: Update 4th --- pages/anime/[...id].js | 60 ++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 36 deletions(-) (limited to 'pages/anime/[...id].js') diff --git a/pages/anime/[...id].js b/pages/anime/[...id].js index d9ef319..dd9a3d8 100644 --- a/pages/anime/[...id].js +++ b/pages/anime/[...id].js @@ -7,7 +7,6 @@ import Head from "next/head"; import { closestMatch } from "closest-match"; import Content from "../../components/hero/content"; -import Image from "next/image"; import { useSession } from "next-auth/react"; @@ -23,7 +22,6 @@ export default function Himitsu({ }) { const [isLoading, setIsloading] = useState(false); const [showText, setShowtext] = useState(false); - const [title, setTitle] = useState(info.title.english || info.title.romaji); const [load, setLoad] = useState(true); const [Lang, setLang] = useState(true); const [showAll, setShowAll] = useState(false); @@ -31,6 +29,7 @@ export default function Himitsu({ const { data: session } = useSession(); const [lastPlayed, setLastPlayed] = useState(null); + const [user, setUser] = useState(null); const episode = episodeList; const epi1 = episode1; @@ -44,13 +43,22 @@ export default function Himitsu({ setLang(false); } - // const { ref } = useParallax({ speed: 10 }); - useEffect(() => { - const playedStr = JSON.parse(localStorage.getItem("lastPlayed")); - setLastPlayed( - playedStr?.filter((item) => item.title === info.title.romaji)[0]?.data - ); + async function userData() { + setLoad(false); + if (!session) return; + setLoad(true); + const res = await fetch(`/api/get-user?userName=${session?.user.name}`); + const data = await res.json(); + setLastPlayed( + data?.recentWatch.filter( + (item) => item.title.romaji === info.title.romaji + )[0]?.episode + ); + setUser(data); + setLoad(false); + } + function getBrightness(color) { const rgb = color.match(/\d+/g); return (299 * rgb[0] + 587 * rgb[1] + 114 * rgb[2]) / 1000; @@ -71,22 +79,9 @@ export default function Himitsu({ elements.forEach((element) => { setTextColor(element); }); - }, [color]); - - // const handleStore = (props) => { - // let existingData = JSON.parse(localStorage.getItem("recentWatch")); - // if (!Array.isArray(existingData)) { - // existingData = []; - // } - // const index = existingData.findIndex( - // (item) => item.title.romaji === props.title.romaji - // ); - // if (index !== -1) { - // existingData.splice(index, 1); - // } - // const updatedData = [props, ...existingData]; - // localStorage.setItem("recentWatch", JSON.stringify(updatedData)); - // }; + + userData(); + }, [color, session]); if (!info) { return; @@ -113,18 +108,9 @@ export default function Himitsu({ "Content-Type": "application/json", }, }); - // console.log(res.status); + console.log(res.status); } - // console.log({ NEXT: subIndo }); - - // console.log(episodeIndo); - - // console.log(lastPlayed); - - function handleLoad() { - setLoad(false); - } return ( <> @@ -430,12 +416,14 @@ export default function Himitsu({
- {episode && Lang ? ( + {load ? ( +

Loading...

+ ) : episode && Lang ? ( episode.map((episode, index) => { const item = lastPlayed?.find( (item) => item.id === episode.id ); - // console.log(item); + console.log(item); return (